package com.ssy.lingxi.pay.controller.pc;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.pay.model.vo.request.*;
import com.ssy.lingxi.pay.model.vo.response.*;
import com.ssy.lingxi.pay.service.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @menu 支付与结算能力-授信处理
 * @author 伍将
 * @date 2020/8/17 17:45
 * @version 2.0.0
 */
@RestController
@RequestMapping("/pay/credit/handle")
public class CreditHandleController extends BaseController {

    @Resource
    private ICreditService creditService;

    @Resource
    private ICreditApplyService creditApplyService;

    @Resource
    private ICreditVerifyService creditVerifyService;

    @Resource
    private ICreditBillService billService;

    @Resource
    private ICreditTradeRecordService tradeRecordService;

    /**
     * 授信额度管理-分页查询授信信息
     * @author 伍将
     * @date 2020/8/17
     **/
    @RequestMapping(value = "/pageCredit", method = RequestMethod.GET)
    public Wrapper<PageData<ChildCreditQueryVO>> pageCredit(HttpServletRequest httpRequest, @Valid PageQueryChildCreditVO pageVO) {
        return creditService.pageChildCredit(getSysUser(httpRequest), pageVO);
    }

    /**
     * 授信额度管理-授信额度详情
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping(value = "/getCreditDetail", method = RequestMethod.GET)
    public Wrapper<CreditDetailVO> getDetail(HttpServletRequest httpRequest, Long id) {
        return creditService.getDetail(getSysUser(httpRequest), id, true);
    }

    /**
     * 授信额度管理-授信调额
     * @author 伍将
     * @date 2020/8/29
     **/
    @RequestMapping("/adjustQuota")
    public Wrapper<Long> creditAdjustQuota(HttpServletRequest httpRequest, @RequestBody @Valid CreditAdjustQuotaVO adjustQuotaVO) {
        return creditApplyService.adjustQuota(getSysUser(httpRequest), adjustQuotaVO);
    }

    /**
     * 授信额度管理-修改授信状态（冻结/解除）
     * @author 伍将
     * @date 2020/8/14
     **/
    @RequestMapping("/updateStatus")
    public Wrapper<Long> updateCreditStatus(HttpServletRequest httpRequest, @RequestBody @Valid CreditUpdateVO updateVO) {
        return creditService.updateCreditStatus(getSysUser(httpRequest), updateVO);
    }

    /**
     * 授信额度管理-授信额度详情-确认还款
     * @author 伍将
     * @date 2020/8/28
     **/
    @RequestMapping("/creditConfirmRepay")
    public Wrapper<Void> creditConfirmRepay(HttpServletRequest httpRequest, @RequestBody @Valid CreditConfirmRepayVO confirmRepayVO) {
        return creditService.confirmRepay(getSysUser(httpRequest), confirmRepayVO);
    }


    /**
     * 授信额度管理-授信额度详情-查询账单详情
     * @author 伍将
     * @date 2020/8/28
     **/
    @RequestMapping(value = "/getCreditBillDetail", method = RequestMethod.GET)
    public Wrapper<CreditBillDetailVO> getBillDetail(HttpServletRequest httpRequest, Long id) {
        return billService.getDetail(getSysUser(httpRequest),id);
    }

    /**
     * 授信额度管理-授信额度详情-分页查询交易记录
     * @author 伍将
     * @date 2020/8/28
     **/
    @RequestMapping(value = "/pageCreditTradeRecord", method = RequestMethod.GET)
    public Wrapper<PageData<CreditTradeRecordPageQueryVO>> pageTradeRecord(@Valid PageQueryCreditTradeRecordVO pageVO) {
        return tradeRecordService.pageTradeRecord(pageVO);
    }

    /**
     * 授信额度管理-授信额度详情-分页查询逾期
     * @author 伍将
     * @date 2020/8/28
     **/
    @RequestMapping(value = "/pageCreditOverdue", method = RequestMethod.GET)
    public Wrapper<PageData<CreditOverduePageQueryVO>> pageOverdue(PageQueryCreditOverdueVO pageVO) {
        return billService.pageOverdue(pageVO);
    }

    /**
     * 授信申请单查询-分页查询授信申请单
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping(value = "/pageCreditChildApply", method = RequestMethod.GET)
    public Wrapper<PageData<CreditChildApplyPageQueryVO>> pageCreditChildApply(HttpServletRequest httpRequest, @Valid PageQueryLowerCreditApplyVO pageVO) {
        return creditApplyService.pageChildApply(getSysUser(httpRequest), pageVO);
    }

    /**
     * 获取授信申请单详情
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping(value = "/getApplyDetail", method = RequestMethod.GET)
    public Wrapper<CreditApplyDetailVO> getApplyDetail(HttpServletRequest httpRequest, @Valid CreditApplyGetDetailVO getDetailVO) {
        return creditApplyService.getDetail(getSysUser(httpRequest), getDetailVO, true);
    }


    /**
     * 待提交审核授信申请单-分页查询授信申请单
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping(value = "/pageCreditChildWaitSubmitApply", method = RequestMethod.GET)
    public Wrapper<PageData<CreditChildApplyPageQueryVO>> pageCreditChildWaitSubmitApply(HttpServletRequest httpRequest, @Valid PageQueryCreditChildApplyVO pageVO) {
        return creditApplyService.pageChildWaitSubmitApply(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交审核授信申请单-提交审核授信申请单-修改授信审批信息
     * @author 伍将
     * @date 2020/8/18
     **/
    @RequestMapping("/updateVerify")
    public Wrapper<Long> updateVerify(HttpServletRequest httpRequest, @RequestBody @Valid CreditVerifyUpdateVO updateVO) {
        return creditVerifyService.updateVerify(getSysUser(httpRequest), updateVO);
    }

    /**
     * 待提交审核授信申请单-提交审核授信申请单
     * @author 伍将
     * @date 2020/8/19
     **/
    @RequestMapping("/submitVerifyCreditApply")
    public Wrapper<Void> submitVerifyCreditApply(HttpServletRequest httpRequest, @RequestBody CreditApplyVerifyVO submitVerifyVO) {
        return creditApplyService.submitVerify(getSysUser(httpRequest), submitVerifyVO);
    }

    /**
     * 待审核授信申请单(一级)-分页查询授信申请单
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping(value = "/pageCreditChildWaitVerifyApplyStepOne", method = RequestMethod.GET)
    public Wrapper<PageData<CreditChildApplyPageQueryVO>> pageCreditChildWaitVerifyApplyStepOne(HttpServletRequest httpRequest, @Valid PageQueryCreditChildApplyVO pageVO) {
        return creditApplyService.pageChildWaitVerifyApplyStepOne(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待审核授信申请单(一级)-分页查询授信申请单-审核授信申请单
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping("/verifyStepOne")
    public Wrapper<Void> verifyStepOne(HttpServletRequest httpRequest, @RequestBody CreditApplyVerifyVO submitVerifyVO) {
        return creditApplyService.verifyStepOne(getSysUser(httpRequest), submitVerifyVO);
    }

    /**
     * 待审核授信申请单(二级)-分页查询授信申请单
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping(value = "/pageCreditChildWaitVerifyApplyStepTwo", method = RequestMethod.GET)
    public Wrapper<PageData<CreditChildApplyPageQueryVO>> pageCreditChildWaitVerifyApplyStepTwo(HttpServletRequest httpRequest, @Valid PageQueryCreditChildApplyVO pageVO) {
        return creditApplyService.pageChildWaitVerifyApplyStepTwo(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待审核授信申请单(二级)-分页查询授信申请单-审核授信申请单
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping("/verifyStepTwo")
    public Wrapper<Void> verifyStepTwo(HttpServletRequest httpRequest, @RequestBody CreditApplyVerifyVO submitVerifyVO) {
        return creditApplyService.verifyStepTwo(getSysUser(httpRequest), submitVerifyVO);
    }

    /**
     * 待审核授信申请单(三级)-分页查询授信申请单
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping(value = "/pageCreditChildWaitVerifyApplyStepThree", method = RequestMethod.GET)
    public Wrapper<PageData<CreditChildApplyPageQueryVO>> pageCreditChildWaitVerifyApplyStepThree(HttpServletRequest httpRequest, @Valid PageQueryCreditChildApplyVO pageVO) {
        return creditApplyService.pageChildWaitVerifyApplyStepThree(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待审核授信申请单(三级)-分页查询授信申请单-审核授信申请单
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping("/verifyStepThree")
    public Wrapper<Void> verifyStepThree(HttpServletRequest httpRequest, @RequestBody CreditApplyVerifyVO submitVerifyVO) {
        return creditApplyService.verifyStepThree(getSysUser(httpRequest), submitVerifyVO);
    }

    /**
     * 待确认授信申请单-分页查询授信申请单
     * @author 伍将
     * @date 2020/8/26
     **/
    @RequestMapping(value = "/pageCreditChildWaitConfirmVerifyApply", method = RequestMethod.GET)
    public Wrapper<PageData<CreditChildApplyPageQueryVO>> pageCreditChildWaitConfirmVerifyApply(HttpServletRequest httpRequest, @Valid PageQueryCreditChildApplyVO pageVO) {
        return creditApplyService.pageChildWaitConfirmVerifyApply(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待确认授信申请单-确认授信申请单
     * @author 伍将
     * @date 2020/8/20
     **/
    @RequestMapping("/confirmVerifyCreditApply")
    public Wrapper<Void> confirmVerifyCreditApply(HttpServletRequest httpRequest, @RequestBody CreditApplyVerifyVO submitVerifyVO) {
        return creditApplyService.confirmVerify(getSysUser(httpRequest), submitVerifyVO);
    }

    /**
     * 分页查询会员列表页面搜索条件内容
     * @author 伍将
     * @date 2020/10/16
     **/
    @RequestMapping(value = "/pageItemsBySupplier", method = RequestMethod.GET)
    Wrapper<CreditPageItemsVO> pageItemsBySupplier(HttpServletRequest httpRequest) {
        return creditService.pageItemsBySupplier(getSysUser(httpRequest));
    }
}
